﻿namespace Models
{
    /// <summary>
    /// A query to run
    /// </summary>
    public class Query : ModelBase
    {
        /// <summary>
        /// A list of possible query types that this query can be set to
        /// </summary>
        public enum QueryType
        {
            /// <summary>
            /// SuperQuery will decide how best to run the query based on the query text
            /// </summary>
            Auto = 0,

            /// <summary>
            /// We want this query to return a table of results (SELECT based queries)
            /// </summary>
            Table = 1,

            /// <summary>
            /// We want this query to return a sinlge value or perform an operation (UPDATE, INSERT etc)
            /// </summary>
            Scalar = 2,
        }

        /// <summary>
        /// Create a new query and set the main properties
        /// </summary>
        /// <param name="queryText">The actual query that we are going to run</param>
        /// <param name="typeOfQuery">The type of query to run</param>
        /// <param name="timeOut">The time out in seconds to wait until the query should finish executing</param>
        public Query(string queryText, QueryType typeOfQuery, int timeOut)
        {
            QueryText = queryText;
            TypeOfQuery = typeOfQuery;
            TimeOut = timeOut;
        }

        /// <summary>
        /// The actual query that we are going to run
        /// </summary>
        public string QueryText
        {
            get
            {
                return m_QueryText;
            }
            set
            {
                m_QueryText = value;
                OnPropertyChanged("QueryText");
            }
        }

        /// <summary>
        /// The type of query to run
        /// </summary>
        public QueryType TypeOfQuery
        {
            get
            {
                return m_TypeOfQuery;
            }
            set
            {
                m_TypeOfQuery = value;
                OnPropertyChanged("TypeOfQuery");
            }
        }

        /// <summary>
        /// The time out value for this query in seconds
        /// </summary>
        public int TimeOut
        {
            get
            {
                return m_TimeOut;
            }
            set
            {
                m_TimeOut = value;
                OnPropertyChanged("TimeOut");
            }
        }

        /// <summary>
        /// Member variables used by properties
        /// </summary>
        private string m_QueryText;
        private int m_TimeOut;
        private QueryType m_TypeOfQuery;
    }
}
